package com.BCM.controller;


import com.BCM.po.CClass;

import com.BCM.po.Grade;
import com.BCM.service.CClassService;

import com.BCM.service.GradeService;
import com.BCM.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author tanghao
 */
@Controller("cclass")
public class CClassController {
    @Autowired
    private CClassService cclassService ;
    @Autowired
    private GradeService gradeService ;
    @Autowired
    private UserService userService;
    @RequestMapping(value = "/CClassList.action")
    public String CClassList(Model model){
        CClass cclass=new CClass();
        List<CClass>cclasses=cclassService.findAllCClass();
        model.addAttribute("cClasses",cclasses);
        return "CClassList";
    }
    @RequestMapping("/findGradeBystudentClass")
    public String findGradeBystudentClass(String studentClass,Model model) {
        System.out.println("studentClass:"+studentClass);
        List<Grade> grades=this.gradeService.findGradeBystudentClass(studentClass);
        for (Grade grade:grades){
            System.out.println("controller"+grade);
        }
        model.addAttribute("Grades",grades);
        return "ClassGradeList";
    }

    @RequestMapping("findAllClass.action")
    @ResponseBody
    public List<CClass> findAllClass(){
        System.out.println("findAllClass");
        CClass cclass=new CClass();
        List<CClass>cclasses=cclassService.findAllCClass();
        return cclasses;
    }


    @RequestMapping("/toClassAdd")
    public String toClassAdd(Model model){
        System.out.println("toClassAdd");
        return "/ClassAdd";
    }

    @RequestMapping("addClass.action")
    public String addClass(CClass cClass){
        System.out.println("findAllClass");
        CClass cclass=new CClass();
        cclassService.save(cClass);
        return  "ClassGradeList";
    }

}
